<template>
    <view>
        <custom>
            <template #backText>{{page.crud_name}}商品</template>
            <template #right v-if="page.form.item_id">
                <view class="action" @tap="deleteDialog = true">
                    <text class="cuIcon-delete"></text>
                </view>
            </template>
        </custom>
        <steps v-if="page.step||!page.form.item_id" class="padding-top-10 padding-bottom-16" :names="['添加商品', '选择分类', '添加属性']"
            :index="page.step||1"></steps>
        <navTabs v-else :tab.sync="tab" :changeTab="key => tab.cur = key"></navTabs>
        <view v-show="(!page.step||page.step==1)&&(!tab.cur||tab.cur==0)">
            <nBar title="基础信息"></nBar>
            <nFormItem key="form_open_status" type="switch" title="上架状态" :data.sync="data" field="open_status"></nFormItem>
            <nFormItem key="form_sort" title="商品排序" format="number" :data.sync="data" field="sort"></nFormItem>
            <nFormItem key="form_is_seller_is_firm" v-if="$store.state.user.identity_info.is_seller==1&&$store.state.user.identity_info.is_firm==1"
                type="checkbox_fields" title="商品属于" :data.sync="data" :checkbox_values="$store.state.user.seller_firm_checkbox_values"></nFormItem>
            <nFormItem key="form_send_channel_id" type="radio_list" title="发货渠道" :data.sync="data" field="send_channel_id"
                :radio_list="page.send_channel_list"></nFormItem>
            <nFormItem key="form_category_1" :is_must="true" type="radio_list" title="商品类型" placeholder="请选择商品类型"
                :data.sync="data" field="category_1" :radio_list="page.seller_item_category"></nFormItem>
            <nFormItem key="form_name" :is_must="true" title="商品名称" :data.sync="data" field="name" maxlength="30"></nFormItem>
            <nFormItem key="form_content" :is_must="true" type="textarea" title="商品描述" :data.sync="data" field="content"
                value="最多50个字" maxlength="50" row="2"></nFormItem>

            <template v-if="!page.form.item_id || data.formbak.attr_key_1">
                <nBar title="属性信息（选填）" right_title="例: 尺寸、颜色、重量"></nBar>
                <nFormItem key="form_attr_key_1" title_em="5" title="属性类型一" placeholder="(选填)商品有几个属性请在创建时确定" :data.sync="data" field="attr_key_1"
                    maxlength="7"></nFormItem>
                <template v-if="!page.form.item_id || data.formbak.attr_key_2">
                    <nFormItem key="form_attr_key_2" title_em="5" title="属性类型二" placeholder="(选填)商品有几个属性请在创建时确定" :data.sync="data"
                        field="attr_key_2" maxlength="7"></nFormItem>
                    <template v-if="!page.form.item_id || data.formbak.attr_key_3">
                        <nFormItem key="form_attr_key_3" title_em="5" title="属性类型三" placeholder="(选填)商品有几个属性请在创建时确定" :data.sync="data"
                            field="attr_key_3" maxlength="7"></nFormItem>
                    </template>
                </template>
            </template>

            <nBar title="数量信息"></nBar>
            <nFormItem key="form_buy_amount_min" title="最小购买数量" :data.sync="data" field="buy_amount_min" format="number"
                maxlength="6" :is_0_then_empty="true"></nFormItem>
            <nFormItem key="form_limit_amount_daily" title="每日限购数量" :data.sync="data" field="limit_amount_daily" format="number"
                maxlength="6" :is_0_then_empty="true"></nFormItem>
            <nFormItem key="form_limit_amount_only" title="永久限购数量" :data.sync="data" field="limit_amount_only" format="number"
                maxlength="6" :is_0_then_empty="true"></nFormItem>

            <nBar title="配送信息"></nBar>
            <nFormItem key="form_open_start_time" type="time_to_time" title="上架时间" :data.sync="data" field="open_start_time"
                field2="open_end_time"></nFormItem>
            <nFormItem key="form_is_express_is_same_city_is_to_shop" type="checkbox_fields" title="配送方式" :data.sync="data"
                :checkbox_values="$store.state.user.dict_to_shop_same_city_express"></nFormItem>
            <nFormItem key="form_express_pack_price" v-if="data.form.is_express==1" title="全国邮寄包装费" placeholder="请填写全国邮寄包装费"
                :data.sync="data" field="express_pack_price" format="digit"></nFormItem>
            <nFormItem key="form_same_city_pack_price" v-if="data.form.is_same_city==1" title="同城配送包装费" placeholder="请填写同城配送包装费"
                :data.sync="data" field="same_city_pack_price" format="digit"></nFormItem>
            <nFormItem key="form_to_shop_pack_price" v-if="data.form.is_to_shop==1" title="到店自取包装费" placeholder="请填写到店自取包装费"
                :data.sync="data" field="to_shop_pack_price" format="digit"></nFormItem>

            <nBar title="图片信息"></nBar>
            <nFormItem key="form_banner" :is_must="true" type="image" image_mode="scaleToFill" title="详情首图" value="建议: 宽高1:1 最大像素750*750"
                :data.sync="data" field="banner"></nFormItem>
            <nFormItem key="form_album_1" type="image" title="详情图1" value="建议: 最大宽度像素750" :data.sync="data" field="album_1"></nFormItem>
            <nFormItem key="form_album_2" type="image" title="详情图2" value="建议: 最大宽度像素750" :data.sync="data" field="album_2"></nFormItem>
            <nFormItem key="form_album_3" type="image" title="详情图3" value="建议: 最大宽度像素750" :data.sync="data" field="album_3"></nFormItem>
            <nFormItem key="form_album_4" type="image" title="详情图4" value="建议: 最大宽度像素750" :data.sync="data" field="album_4"></nFormItem>
            <nFormItem key="form_album_5" type="image" title="详情图5" value="建议: 最大宽度像素750" :data.sync="data" field="album_5"></nFormItem>

            <foot :title="page.step||!page.form.item_id?'添加商品，然后进行下一步':'编辑商品'" :tap="submitItem"></foot>
        </view>
        <view v-show="page.step==2 || tab.cur==1">
            <checkbox-group @change="changeItemTypeList">
                <view class="cu-list menu">
                    <nMenuItemContentAction v-for="(info, key) in page.item_type_all_list" :key="key" class="bg-white">
                        <template #content>
                            <label class="flex justify-between align-center">
                                <view>
                                    <view>{{info.name}}</view>
                                    <view>
                                        <view class="cu-tag" v-if="info.open_status == 0">下架</view>
                                        <view class="cu-tag bg-nddyny" v-if="info.open_status == 1">上架</view>
                                        <view class="cu-tag" v-if="info.audit_status == 0">正在审核</view>
                                        <view class="cu-tag bg-nddyny" v-if="info.audit_status == 1">已审核</view>
                                        <view class="cu-tag bg-red" v-if="info.audit_status == 2">审核失败</view>
                                    </view>
                                </view>
                                <view>
                                    <checkbox class="nddyny" :class="page.item_type_ids | inArray(info.item_type_id) ? 'checked' : ''"
                                        :checked="page.item_type_ids | inArray(info.item_type_id) ? true : false"
                                        :value="info.item_type_id"></checkbox>
                                </view>
                            </label>
                        </template>
                    </nMenuItemContentAction>
                </view>
                <foot :title="page.step?'选择分类，然后进行下一步':'编辑分类'" :tap="submitItem"></foot>
            </checkbox-group>
        </view>
        <view v-show="page.step==3 || tab.cur==2">
            <itemAttrChange :is_force_update.sync="is_force_update_item_attr" :itemAttrChange="itemAttrChange" class="padding-lr-30 padding-top-20"
                :data.sync="page"></itemAttrChange>
            <nFormItem key="form_amount_start_amount_end" style="margin-top: -10rpx;" title="库存数量" placeholder="开始(可选)"
                placeholder2="结束(可选)" :data.sync="attr_data" field="amount_start" field2="amount_end"></nFormItem>
            <emptyList v-if="page.item_attr_list.length == 0" empty_list_title="没有商品属性"></emptyList>
            <crud ref="crud" :title="crud.title" :getList="attrListInit" :list.sync="page.item_attr_list" :url_update="crud.url_update"
                :form.sync="crud.form" :upload.sync="crud.upload" class_menu="padding-bottom-20">
                <template #list="crud">
                    <nMenuItemContentAction v-for="(info, key) in crud.list" :key="key">
                        <template #content>
                            <view class="flex">
                                <view class="flex flex-direction flex-sub" v-for="(value, key) in [1, 2, 3]" :key="key">
                                    <view class="text-nddyny text-sm">{{data.form['attr_key_'+value]}}</view>
                                    <view class="text-df">{{info['attr_value_'+value]}}</view>
                                </view>
                            </view>
                            <view class="flex margin-top-10">
                                <image class="radius" :src="info.logo | ossUrl(196)" style="width:196rpx;height:196rpx;"></image>
                                <view class="width-100p flex-sub margin-left-20 margin-right-10">
                                    <view class="flex align-center justify-between">
                                        <view class="flex align-center">
                                            <view class="text-nddyny text-df min-width-em2">排序</view>
                                            <view style="width: 150rpx;">{{info.sort}}</view>
                                        </view>
                                        <view class="flex align-center flex-sub justify-between">
                                            <view class="text-nddyny text-df min-width-em4">默认属性</view>
                                            <view>
                                                <switch class='nddyny radius' @change="setDefaultItemAttr(info.item_id, info.item_attr_id)"
                                                    :class="data.form.default_item_attr_id!=info.item_attr_id ? '' : 'checked'"
                                                    :checked="data.form.default_item_attr_id!=info.item_attr_id ? false : true"
                                                    :disabled="data.form.default_item_attr_id==info.item_attr_id"></switch>
                                            </view>
                                        </view>
                                    </view>
                                    <view class="flex align-center">
                                        <view class="text-nddyny text-df min-width-em4">商品价格</view>
                                        <view>
                                            <text class="text-red text-bold">
                                                <text class="text-sm">￥</text>
                                                <text>{{info.price | floor}}</text>
                                            </text>
                                            <text v-if="info.oprice>0" class="text-through text-sm margin-left-10 text-gray">
                                                ￥
                                                <text style="margin-left: -4rpx">{{info.oprice | floor}}</text>
                                            </text>
                                        </view>
                                    </view>
                                    <view class="flex align-center">
                                        <view class="text-nddyny text-df min-width-em4">赠送金券</view>
                                        <view>{{info.bonus_gold_coupon_ratio}}<text class="margin-left-2">%</text></view>
                                    </view>
                                    <view class="flex align-center">
                                        <view class="text-nddyny text-df min-width-em4">库存数量</view>
                                        <view>{{info.amount}}</view>
                                    </view>
                                </view>
                            </view>
                            <view class="flex justify-between margin-top-16">
                                <view>
                                    <view class="cu-tag" v-if="info.open_status == 0">下架</view>
                                    <view class="cu-tag bg-nddyny" v-if="info.open_status == 1">上架</view>
                                    <view class="cu-tag" v-if="info.audit_status == 0">正在审核</view>
                                    <view class="cu-tag bg-nddyny" v-if="info.audit_status == 1">已审核</view>
                                    <view class="cu-tag bg-red" v-if="info.audit_status == 2">审核失败</view>
                                </view>
                                <view>
                                    <template v-if="page.item_attr_id && page.item_attr_id == info.item_attr_id">
                                        {{attrUpdate(info)}}
                                    </template>
                                    <nButton title="删除" bg="bg-red" class="sm" :tap="()=>{$refs.crud.delete(info)}"></nButton>
                                    <nButton title="编辑" class="margin-left-10 sm" :tap="()=>{attrUpdate(info)}"></nButton>
                                </view>
                            </view>
                        </template>
                    </nMenuItemContentAction>
                </template>
                <template #form="crud">
                    <template v-if="crud && crud.dialog && crud.dialog.show">
                        <template v-if="crud.data.form.is_delete==1">
                            <view class="text-center">
                                确定要删除商品属性
                                <text v-if="crud.data.form.attr_value_1">
                                    “{{crud.data.form.attr_value_1}}
                                    <text v-if="crud.data.form.attr_value_2">.{{crud.data.form.attr_value_2}}</text>
                                    <text v-if="crud.data.form.attr_value_3">.{{crud.data.form.attr_value_3}}</text>
                                    ”
                                </text>
                                吗？
                            </view>
                        </template>
                        <template v-else>
                            <nFormItem key="form_open_status" type="switch" title="上架状态" :data.sync="crud.data" field="open_status"
                                :disabled="crud.data.form.is_delete==1?true:false"></nFormItem>
                            <nFormItem key="form_sort" title="属性排序" format="number" :data.sync="crud.data" field="sort"
                                :disabled="crud.data.form.is_delete==1?true:false"></nFormItem>
                            <nFormItem key="form_logo" :is_must="true" type="image" image_mode="scaleToFill" title="属性图片"
                                value="建议: 宽高750px*750px" :data.sync="crud.data" field="logo" image_width="520"
                                image_height="520"></nFormItem>
                            <nFormItem key="form_attr_value_1" v-if="data.form.attr_key_1" :is_must="true" :title="data.form.attr_key_1"
                                :placeholder="'请填写'+data.form.attr_key_1" :data.sync="crud.data" field="attr_value_1"
                                maxlength="15"></nFormItem>
                            <nFormItem key="form_attr_value_2" v-if="data.form.attr_key_1 && data.form.attr_key_2"
                                :is_must="true" :title="data.form.attr_key_2" :placeholder="'请填写'+data.form.attr_key_2"
                                :data.sync="crud.data" field="attr_value_2" maxlength="15"></nFormItem>
                            <nFormItem key="form_attr_value_3" v-if="data.form.attr_key_1 && data.form.attr_key_2 && data.form.attr_key_3"
                                :is_must="true" :title="data.form.attr_key_3" :placeholder="'请填写'+data.form.attr_key_3"
                                :data.sync="crud.data" field="attr_value_3" maxlength="15"></nFormItem>
                            <nFormItem key="form_oprice" title="商品原价" placeholder="请填写商品原价(选填)" :data.sync="crud.data"
                                field="oprice" :is_0_then_empty="true" format="digit"></nFormItem>
                            <nFormItem key="form_price" :is_must="true" title="商品价格" :data.sync="crud.data" field="price"
                                format="digit"></nFormItem>
                            <nFormItem key="form_amount" :is_must="true" title="库存数量" :data.sync="crud.data" field="amount"
                                format="number"></nFormItem>
                            <nFormItem key="form_bonus_gold_coupon_ratio" title_em="6" :is_must="true" title="赠送金券比例"
                                :data.sync="crud.data" field="bonus_gold_coupon_ratio" format="number"></nFormItem>
                        </template>
                    </template>
                </template>
            </crud>
        </view>
        <modalDialog :show.sync="deleteDialog" :confirm="submitItem" content="确定要删除该商品吗？">
        </modalDialog>
    </view>
</template>

<script>
    import crud from '@/components/nddyny/crud.vue';
    import steps from '@/components/nddyny/steps.vue';
    import itemAttrChange from './components/itemAttrChange.vue';
    export default {
        components: {
            crud,
            steps,
            itemAttrChange
        },
        data() {
            let form = {
                default_item_attr_id: '',

                delete_sitm_ids: '',
                insert_item_type_ids: '',

                item_id: '',
                is_delete: '',

                // 基础信息
                open_status: '1',
                sort: '0',
                is_seller: this.$store.state.user.identity_info.is_seller,
                is_firm: this.$store.state.user.identity_info.is_firm,
                send_channel_id: '0',
                category_1: '0',
                name: '',
                content: '',

                // 属性信息
                attr_key_1: '',
                attr_key_2: '',
                attr_key_3: '',

                // 数量信息
                buy_amount_min: 0,
                limit_amount_daily: 0,
                limit_amount_only: 0,

                // 配送信息
                open_start_time: '0',
                open_end_time: '0',
                is_to_shop: 0,
                is_same_city: 0,
                is_express: 0,
                to_shop_pack_price: 0,
                same_city_pack_price: 0,
                express_pack_price: 0,

                // 图片信息
                banner: '',
                album_1: '',
                album_2: '',
                album_3: '',
                album_4: '',
                album_5: '',
            };
            return {
                deleteDialog: false,
                is_force_update_item_attr: false,
                tab: {
                    cur: '',
                    list: {
                        0: {
                            title: '商品'
                        },
                        1: {
                            title: '分类'
                        },
                        2: {
                            title: '属性'
                        }
                    }
                },
                page: {
                    step: '',
                    item_attr_id: '',
                    crud_name: '',
                    form: {
                        item_id: ''
                    },
                    send_channel_list: [],
                    item_type_all_list: [],
                    item_type_list: [],
                    item_info: {},
                    item_attr_list: [],
                    item_attr_list_bak: [],
                    seller_item_category: this.$dict.seller_item_category,

                    item_type_ids: [],
                    item_type_ids_bak: [],
                    item_type_id_middle_list: {},
                },
                attr_data: {
                    attr_checkbox_value_1: '',
                    attr_checkbox_value_2: '',
                    attr_checkbox_value_3: '',
                    formtag: {},
                    form: {
                        amount_start: '',
                        amount_end: '',
                    },
                    formbak: {
                        amount_start: '',
                        amount_end: '',
                    }
                },
                data: {
                    formtag: {},
                    form: this.$nddyny.object.copy(form),
                    formbak: this.$nddyny.object.copy(form),
                },
                crud: {
                    title: '商品属性',
                    url_update: '/seller/item/updateAttr',
                    form: {
                        is_seller: 1,
                        is_firm: 1,
                        open_status: '1',
                        is_delete: '',
                        item_attr_id: '',
                        item_id: '',
                        sort: '0',
                        logo: '',
                        attr_value_1: '',
                        attr_value_2: '',
                        attr_value_3: '',
                        oprice: '',
                        price: '',
                        amount: '',
                        bonus_gold_coupon_ratio: '',
                    },
                    upload: {
                        uri: '/seller/item/uploadAttr',
                        fields: ['logo'],
                    }
                },
            };
        },
        onLoad(params) {
            if (params.item_id) {
                this.page.form.item_id = params.item_id;
                this.page.step = params.step;
            }
            if (params.item_attr_id) {
                this.page.item_attr_id = params.item_attr_id;
                this.tab.cur = 2;
            }
            this.pageInit();
        },
        watch: {
            'attr_data.form.amount_start'() {
                this.itemAttrChange(null, null, null);
            },
            'attr_data.form.amount_end'() {
                this.itemAttrChange(null, null, null);
            }
        },
        methods: {
            attrUpdate(info) {
                if (this.page.item_attr_id) {
                    this.page.item_attr_id = '';
                }
                this.$refs.crud.update(info);
            },
            itemAttrChange(attr_checkbox_value_1, attr_checkbox_value_2, attr_checkbox_value_3, item_attr_info) {
                if (attr_checkbox_value_1 === null) {
                    attr_checkbox_value_1 = this.attr_data.attr_checkbox_value_1;
                } else {
                    this.attr_data.attr_checkbox_value_1 = attr_checkbox_value_1;
                }
                if (attr_checkbox_value_2 === null) {
                    attr_checkbox_value_2 = this.attr_data.attr_checkbox_value_2;
                } else {
                    this.attr_data.attr_checkbox_value_2 = attr_checkbox_value_2;
                }
                if (attr_checkbox_value_3 === null) {
                    attr_checkbox_value_3 = this.attr_data.attr_checkbox_value_3;
                } else {
                    this.attr_data.attr_checkbox_value_3 = attr_checkbox_value_3;
                }
                let item_attr_list = [];
                this.page.item_attr_list_bak.forEach(info => {
                    if (
                        (!attr_checkbox_value_1 || attr_checkbox_value_1 == info.attr_value_1) &&
                        (!attr_checkbox_value_2 || attr_checkbox_value_2 == info.attr_value_2) &&
                        (!attr_checkbox_value_3 || attr_checkbox_value_3 == info.attr_value_3) &&
                        (!this.attr_data.form.amount_start || info.amount * 1 >= this.attr_data.form.amount_start *
                            1) &&
                        (!this.attr_data.form.amount_end || info.amount * 1 <= this.attr_data.form.amount_end *
                            1)
                    ) {
                        item_attr_list.push(info);
                    }
                });
                this.page.item_attr_list = item_attr_list;
            },
            pageInit(message) {
                if (this.page.form.item_id) {
                    if (this.page.step) {
                        this.page.crud_name = '添加';
                    } else {
                        this.page.crud_name = '编辑';
                        if (!this.tab.cur) {
                            this.tab.cur = 0;
                        }
                    }
                    this.$api.post(this, {
                        url: '/seller/item/info',
                        data_key: 'page',
                        success: (Result, data_key) => {
                            if (this.$api.form.toast(this, Result, data_key)) return;
                            if (message) {
                                this.$store.commit('userToastSuccess', message);
                            }

                            this.page.send_channel_list = Result.result.send_channel_list;
                            this.page.item_type_all_list = Result.result.item_type_all_list;
                            this.page.item_type_list = Result.result.item_type_list;
                            this.page.item_info = Result.result.item_info;
                            this.page.item_attr_list = this.$nddyny.object.copy(Result.result.item_attr_list);

                            this.setSendChannelList();
                            Object.keys(this.page.item_info).forEach(key => {
                                if (this.data.form[key] != null) {
                                    this.data.form[key] = this.page.item_info[key];
                                }
                            });
                            let item_type_id_middle_list = {};
                            Object.keys(this.page.item_type_list).forEach(key => {
                                item_type_id_middle_list[this.page.item_type_list[key].item_type_id] =
                                    this.page.item_type_list[key].sitm_id;
                            })
                            this.page.item_type_id_middle_list = item_type_id_middle_list;
                            let item_type_ids = [];
                            this.page.item_type_list.forEach(info => {
                                item_type_ids.push(info.item_type_id);
                            })
                            this.page.item_type_ids = this.$nddyny.object.copy(item_type_ids);
                            this.page.item_type_ids_bak = this.$nddyny.object.copy(item_type_ids);

                            this.crud.form.item_id = this.page.form.item_id;

                            this.changeItemTypeList();

                            // start 这个必须放在会影响数据的操作之后, 备份初始的form数据
                            this.data.formbak = this.$nddyny.object.copy(this.data.form);
                            this.$set(this.page, 'item_attr_list_bak', this.$nddyny.object.copy(this.page.item_attr_list));
                            // end

                            if (this.page.step == 3) {
                                this.$refs.crud.insert();
                            }
                        }
                    });
                } else {
                    this.page.crud_name = '添加';
                    this.$api.post(this, {
                        url: '/seller/item/sendChannelList',
                        data_key: 'page',
                        success: (Result, data_key) => {
                            if (this.$api.form.toast(this, Result, data_key)) return;
                            this.page.send_channel_list = Result.result;

                            this.setSendChannelList();
                        }
                    });
                }
            },
            setSendChannelList() {
                this.page.send_channel_list = [{
                    send_channel_id: '0',
                    name: '默认发货渠道',
                }].concat(this.page.send_channel_list);
            },
            submitItem() {
                let is_delete = 0;
                let crud_name = this.page.crud_name;
                let upload = null;
                if (this.deleteDialog) {
                    is_delete = 1;
                    crud_name = '删除';
                } else {
                    upload = {
                        uri: '/seller/item/upload',
                        fields: ['banner', 'album_1', 'album_2', 'album_3', 'album_4', 'album_5'],
                        info_old: this.data.formbak,
                        info_new: this.data.form
                    };
                }
                this.$api.post(this, {
                    loading: crud_name + '商品中',
                    url: '/seller/item/update',
                    upload: upload,
                    data_append: {
                        is_delete: is_delete
                    },
                    success: (Result) => {
                        if (this.$api.form.toast(this, Result)) return;
                        if (this.deleteDialog) {
                            this.deleteDialog = false;
                            this.$store.commit('userToastSuccess', {
                                message: '删除商品成功',
                                commit: 'appBackPage'
                            });
                        } else if (!this.page.form.item_id) {
                            // 添加商品
                            this.$store.commit('userToastSuccess', {
                                message: '添加商品成功',
                                reToUri: '/seller/item/info?step=2&item_id=' + Result.result
                            });
                        } else if (this.page.step == 2) {
                            // 选择分类
                            this.$store.commit('userToastSuccess', {
                                message: '选择分类成功',
                                reToUri: '/seller/item/info?step=3&item_id=' + this.page.form.item_id
                            });
                        } else {
                            // 编辑
                            this.pageInit('编辑商品成功');
                        }
                    }
                });
            },
            changeItemTypeList(e) {
                if (e) {
                    this.page.item_type_ids = e.target.value;
                } else {
                    // 初始化页面数据时，也要初始化 insert_item_type_ids、delete_sitm_ids 
                }
                this.data.form.insert_item_type_ids = this.$nddyny.array.diff(this.page.item_type_ids, this.page.item_type_ids_bak)
                    .join(',');
                let delete_sitm_ids = [];
                this.$nddyny.array.diff(this.page.item_type_ids_bak, this.page.item_type_ids).forEach(id => {
                    delete_sitm_ids.push(this.page.item_type_id_middle_list[id]);
                })
                this.data.form.delete_sitm_ids = delete_sitm_ids.join(',');
            },
            attrListInit(item_attr_id) {
                if (this.page.step == 3 && item_attr_id) {
                    this.setDefaultItemAttr(this.page.form.item_id, item_attr_id, () => {
                        this.$store.commit('userToastSuccess', {
                            message: '添加属性成功',
                            reToUri: '/seller/item/info?item_id=' + this.page.form.item_id
                        });
                    })
                } else {
                    this.pageInit(this.page.crud_name + '属性成功');
                    this.is_force_update_item_attr = true;
                }
            },
            setDefaultItemAttr(item_id, item_attr_id, callback) {
                this.$api.post(this, {
                    url: '/seller/item/setDefaultItemAttr',
                    data_key: null,
                    data_append: {
                        item_id: item_id,
                        default_item_attr_id: item_attr_id,
                    },
                    success: (Result, data_key) => {
                        if (this.$api.form.toast(this, Result, data_key)) return;
                        if (callback) {
                            callback();
                        } else {
                            this.pageInit('设置默认成功');
                        }
                    }
                });
            }
        },
    }
</script>
